﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;
using Common;
using Basic.Business;
using Basic.Model.Entity;

public partial class Basic_Background_MenuViewByTree : System.Web.UI.Page
{
    protected string treeListStr = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        //强制刷新页面
        Response.Buffer = true;
        Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
        Response.Expires = 0;
        Response.CacheControl = "no-cache";
        Response.AppendHeader("Pragma", "No-Cache");

        //判断用户是否登录
        if (!Tools.IsAdminSessionValid())
            Tools.ShowInfo(StringTable.ErrorSessionTimeOut, "../Background/AdminLogin.aspx", "_self");
        StringBuilder _treeListStr = new StringBuilder();
        IList<MenuNode> list = MenuNodeAdmin.GetAllByTree();
        buildTreeList(_treeListStr, list, 0);
        treeListStr = _treeListStr.ToString();
    }
    protected void buildTreeList(StringBuilder _treeListStr, IList<MenuNode> list, int menuParentId)
    {
        Basic.VO.Admin admin=(Basic.VO.Admin)Session["Admin"];
        foreach (MenuNode menuNode in list)
        {
            if (menuNode.menuParentId == menuParentId&&!String.IsNullOrEmpty(menuNode.roleKey))
            {
                if (String.IsNullOrEmpty(menuNode.menuUrl))
                {
                    if(RoleAdmin.CheckRole(menuNode.roleKey,admin.adminGroup.roleNames))
                        _treeListStr.AppendFormat("<li class=\"folder f-open first\"><span>{0}</span><ul>", menuNode.menuName);
                }
                else
                {
                    if(RoleAdmin.CheckRole(menuNode.roleKey,admin.adminGroup.roleNames))
                        _treeListStr.AppendFormat("<li class=\"doc\"><span><a onclick=\"MUI.openByPanel('{0}','{1}');\">{0}</a></span></li>", menuNode.menuName, menuNode.menuUrl);
                }
                buildTreeList(_treeListStr, list, menuNode.menuId);
                if (String.IsNullOrEmpty(menuNode.menuUrl))
                {
                    if(RoleAdmin.CheckRole(menuNode.roleKey,admin.adminGroup.roleNames))
                        _treeListStr.Append("</ul></li>");
                }
            }
        }
    }
}
